package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.base.Page;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product")
public class SpuManageController {
    @Autowired
    private SpuManageService spuManageService;



    @GetMapping("/{pageNum}/{pageSize}")
    public Result getSpuByPage(@PathVariable Long pageNum,
                             @PathVariable Long pageSize,
                             @RequestParam Long category3Id){

      Page<SpuInfo> spuInfoPage  =spuManageService.getSpuByPage(pageNum,pageSize,category3Id);
      return Result.ok(spuInfoPage);
    }

    //添加商品spu
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuManageService.saveSpuInfo(spuInfo);
      return   Result.ok();
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result getSpuImageList(@PathVariable Long spuId){
     List<SpuImage>  spuImageList =  spuManageService.getSpuImageList(spuId);
        return Result.ok(spuImageList);
    }


    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result  getSpuSaleAttrList(@PathVariable Long spuId){
      List<SpuSaleAttr> spuSaleAttrList  =spuManageService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }
}
